﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Superstore.Store.Models;

namespace Superstore.Store.Controllers
{
    public class DeliveryAddrController : Controller
    {
        // GET: DeliveryAddr
        public ActionResult Index(string redirectUrl = "")
        {
            if (redirectUrl != "")
            {
                ViewBag.redirectUrl = redirectUrl;
            }
            return View();
        }

        public ActionResult Add()
        {
            return View();
        }

        public ActionResult Edit()
        {
            return View();
        }

        public PartialViewResult GetDeliveryAddressList(List<DeliveryAddrInfo> deliveryAddressList, int defaultDeliveryAddressIndex, string redirectUrl = "")
        {
            if (deliveryAddressList != null && deliveryAddressList.Count > 0)
            {
                if (defaultDeliveryAddressIndex < 0 || defaultDeliveryAddressIndex >= deliveryAddressList.Count)
                {
                    ViewBag.addrId = "";
                }
                else
                {
                    ViewBag.addrId = deliveryAddressList[defaultDeliveryAddressIndex].id;
                }
                ViewBag.redirectUrl = redirectUrl;
                return PartialView("GetDeliveryAddressList", deliveryAddressList);
            }
            ViewBag.defaultDeliveryAddressIndex = -1;
            return PartialView("GetDeliveryAddressList");
        }
    }
}